<?php 
$holiday = 0;$absent = 0;$unpaid_leave = 0;$paid_leave = 0;$tot_time = 0;$dbtime_tot=0;$half_day=0;$present=0;$per_day=0;
?>
<div class="row-fluid">

<div class="span9">
<h3><?php echo $this->ion_auth->get_username($this->uri->segment(4))?> attendance sheet for month of  <?php

 echo $monthName = date("F", mktime(0, 0, 0, $this->uri->segment(6), 10));
 
 ?></h3>
 
<table class="table table-striped table-hover table-condensed" width="100%">	
		<tr class="text-info">
			<td>Date</td>
			<td>Entry Time</td>
			<td>Lunch In Time</td>
			<td>Lunch Out Time</td>
			<td>Exit Time</td>
			<td>Total Working Hours</td>
			<td>Action</td>			
		</tr>	
	<tbody>
	<?php 
	
	foreach($daily_sheets as $daily_sheet){?>
	<?php for($i=1;$i<=$num;$i++){
		
		if($i<10)
		{
		$day = 'day_0'.$i;	
		$date_id = '0'.$i;
		}
	else{
		$day = 'day_'.$i;
		$date_id = $i;
		}
		?>
		
	<tr <?php if($daily_sheet->$day=='sunday'){?> class="text-error error" <?php }?> >
		<td><?php echo date("F", mktime(0, 0, 0, $this->uri->segment(6), 10)).' '.$date_id?></td>
		<td>
		<?php 		
		$time_details = $this->all_attendance_model->get_time($user_id,$daily_sheet->year_id,$daily_sheet->month_id,$date_id);		
		if(!empty($time_details['entry_time'])){			
		if(!empty($time_details['entry_flag']) && $time_details['entry_flag']==1): 
		echo '<span class="text-warning">'.DATE("g:i a", STRTOTIME($time_details['entry_time']));
		else:	
		echo DATE("g:i a", STRTOTIME($time_details['entry_time']));
		endif;
		}	
		?>
		</td>
		
		<td>
			<?php 		
		$time_details = $this->all_attendance_model->get_time($user_id,$daily_sheet->year_id,$daily_sheet->month_id,$date_id);		
		if(!empty($time_details['lunch_in_time'])){			
		if(!empty($time_details['lunch_in_flag']) && $time_details['lunch_in_flag']==1): 
		echo '<span class="text-warning">'.DATE("g:i a", STRTOTIME($time_details['lunch_in_time']));
		else:	
		echo DATE("g:i a", STRTOTIME($time_details['lunch_in_time']));
		endif;
		}	
		?>
		</td>
		<td>
			<?php 		
		$time_details = $this->all_attendance_model->get_time($user_id,$daily_sheet->year_id,$daily_sheet->month_id,$date_id);		
		if(!empty($time_details['lunch_out_time'])){			
		if(!empty($time_details['lunch_out_flag']) && $time_details['lunch_out_flag']==1): 
		echo '<span class="text-warning">'.DATE("g:i a", STRTOTIME($time_details['lunch_out_time']));
		else:	
		echo DATE("g:i a", STRTOTIME($time_details['lunch_out_time']));
		endif;
		}	
		?>
		</td>
		
		<td>
		<?php if(!empty($time_details['exit_time'])){
		if(!empty($time_details['exit_flag']) && $time_details['exit_flag']==1): 
		echo '<span class="text-warning">'.DATE("g:i a", STRTOTIME($time_details['exit_time']));
		else:	
		echo DATE("g:i a", STRTOTIME($time_details['exit_time']));
		endif;	
		}?>
		</td>
		<td>
		
				<?php
		$class = NULL;$style = NULL;$tooltips = NULL;
		
		if($daily_sheet->$day == 'holiday'){
			$class = 'text-success';
			$tooltips = 'Pooja';
			$holiday += 1;
		}elseif($daily_sheet->$day == 'absent' OR $daily_sheet->$day == 'rejected'){
			$class = 'text-error';			
			$style = 'text-decoration:line-through;';
			$absent +=1;
		}elseif($daily_sheet->$day == 'paid_leave'){
			$class = 'text-info';
			$paid_leave +=1;
		}elseif($daily_sheet->$day == 'unpaid_leave'){
			$class = 'purple';
			$unpaid_leave += 1;			
		}elseif($daily_sheet->$day == 'sunday'){
			
		}elseif(!empty($daily_sheet->$day)){
					/*calulation of present days*/
					$present +=1;
					
					if(!empty($daily_sheet->$day)){					
					$dbtime_explode = explode(':',$daily_sheet->$day);
		 			$dbtot_hr 		= $dbtime_explode[0]*60*60;
					$dbtot_min		= $dbtime_explode[1]*60;				
					$dbtime_tot 	+= $dbtot_hr + $dbtot_min;
					}
					/*calulation of half day*/
					if($dbtime_explode[0] < 4){
						$half_day +=1;						
					}
					
			//$tot_time += strtotime($daily_sheet->$day);
		}
		?>
		
		<span class="<?= $class;?>" style="<?= $style;?>" >
		 <a href="javascript:void(0)" class="<?= $class;?> tooltips" title="<?php echo $tooltips;?>" ><?php echo ucfirst($daily_sheet->$day);?></a>
		</span>	
	
		</td>	
		<td><!--<a href="<?php echo site_url('founder/attendance/delete_attendance').'/'.$time_details['id']?>"><i class="icon-trash"></i></a>--></td>	
	</tr>
	<?php }}?>	
	</tbody>
</table>

</div>
<div class="span3">
<a href="<?= site_url('user/attendance/edit_attendance')?>">Edit Attendance</a> / 
<a href="<?php echo site_url('founder/salary/salary_slip/'.$this->uri->segment(4).'/'.$this->uri->segment(6).'/'.$this->uri->segment(5)); ?>">Salary Slip</a>
<h4 class="widget-name" >Attendance Sheet</h4>
<ul style="height:105px; overflow-y: scroll;">
<?php foreach($attendance as $attend){?>
<li><a href="<?php echo site_url('founder/attendance/index').'/'.$user_id.'/'.$attend->year_id.'/'.$attend->month_id?>"><?php echo date("F",mktime(0, 0, 0,$attend->month_id, 10));?></a></li>
<?php }?>
</ul>

<h4 class="widget-name">Monthly Status</h4>

<table class="table table-condensed table-bordered">
<tr>
	<td>No. of Working Days</td>
	<td class="text-info">: <?php echo (element('working_days',$global_data,NULL)-$holiday);?> days</td>
	<tr>
	<td>Holidays</td>
	<td class="text-success">: <?php echo $holiday;?> days</td>
	</tr>
	<tr>
		<td>Total Working Hrs</td>
		<td class="text-error">: <?php echo (element('total_working_hour',$global_data,NULL));?> hrs</td>
	</tr>
	<tr>
		<td>Average</td>
		<td>: <?php echo (element('min_working_hour',$global_data,NULL));?> hrs</td>
	</tr>
</tr>
</table>
<h5 class="orange">My Status</h5>
<table class="table table-condensed table-bordered">
	<tr>
		<td>Present</td>
		<td><?php echo $present;?> days</td>
	</tr>
	<tr>
		<td>Absent</td>
		<td><?php echo $absent;?> days</td>
	</tr><tr>
		<td>Total Working Hr</td>
		<td>
		<?php		
		echo $bhours 		= floor(abs($dbtime_tot)/ 3600);
		echo ":";
		echo $bminutes 		= floor((abs($dbtime_tot) / 60) % 60);
		echo ' hr';
		?>
		</td>
	</tr>
	<tr>
		<td>Average</td>
		<td><?php 
		$average = ($dbtime_tot / $present);
		echo $ahours 		= floor(abs($average)/ 3600);
		echo ":";
		echo $min 		= floor((abs($average) / 60) % 60);		
		echo ' hr';
		
		?></td>
	</tr>
	<tr>
		<td>Paid Leave</td>
		<td><?php echo $paid_leave;?></td>
	</tr>
	<tr>
		<td>Unpaid Leave</td>
		<td><?php echo $unpaid_leave;?></td>
	</tr>
	<tr>
		<td>Half day</td>
		<td><?php echo $half_day;?></td>
	</tr>
	
</table>
<h5 class="widget-name">My Worksheet Status <small> <a href="<?php echo site_url();?>"> check worksheet </a></small></h5>
<table class="table table-bordered table-condensed">
<tr>
	<td> <a href="javascript:void(0);" class="tooltips" title="It is empty" data-placement="left" >Absent</a> </td>
	<td> <?php echo $worksheet_status['absent'];?> </td>
</tr>
<tr>
	<td><a href="javascript:void(0);" class="tooltips" title="Working time is less than 4 hours" data-placement="left" >Half Day</a></td>
	<td> <?php echo $worksheet_status['half_day'];?></td>
</tr>
<tr>
	<td><a href="javascript:void(0);" class="tooltips" title="Working time is less than 2 hours" data-placement="left" >Unpaid</a></td>
	<td> <?php echo $worksheet_status['unpaid'];?></td>
</tr>
<tr>
	<td><a href="javascript:void(0);" class="tooltips" title="If entry time is greater than 10.00" data-placement="left">Fine</a></td>
	<td> <?php echo $fine['fine_amount'];?></td>
</tr>
</table>

<h4 class="widget-name">Salary Slip details </h4>
<?php if(isset($my_salary['basic_pay'])){?>
<table width="100%" class="table table-condensed">
<tr class="text-success success">
<td width="60%"  class="text-success" style="font-weight: bold;">My Salary <br /> <small>Per day</small> </td>
<td width="40%">: Rs. <?php echo $my_salary['basic_pay'];?> <br /> : <small><?php echo $per_day = round($my_salary['basic_pay']/30,2); ?> </small></td>
</tr>
<tr>
	<td colspan="2">
	<span class="text-error" style="font-weight: bold;">Deduction</span>
	<table class="table table-condensed" width="100%">	
	<tr>
		<td width="60%">Absent <small>(perday X 2)</small></td>
		<td>
			<?php 
			echo $ded_absent = round($absent * ($per_day * 2),2);
			?>			
		</td>
	</tr>
	<tr>
		<td>Unpaid <small>(perday)</small></td>
		<td>
			<?php 
			echo $ded_unpaid = round($unpaid_leave * ($per_day),2);
			?>			
		</td>
	</tr>
	<tr>
		<td>Half Day <small>(perday / 2)</small></td>
		<td>
			<?php 
			echo $ded_half_day = round($half_day * ($per_day / 2),2);
			?>			
		</td>		
	</tr>
	<tr>
		<td>Fine</td>
		<td><?php echo $ded_fine =  $fine['fine_amount'];?></td>
	</tr>
	<tr class="text-error"> 
		<td>Total Deduction</td>
		<td> <?php 
			echo $tot_ded = round(($ded_absent + $ded_unpaid + $ded_half_day + $ded_fine),2);
			?> </td>
	</tr>
</table>
	</td>
</tr>
<tr class="text-success" style="font-weight: bold">
<td>Receivable Salary</td>
<td class="text-error">: 
<?php echo $rs = ($my_salary['basic_pay'] - $tot_ded);?>
</td>
</tr>
<tr>
	<td colspan="2">
			
	</td>
	
</tr>
</table>

<?php }else{ echo '<b>No Salary Has Been Defined For You. Please Contact System Admin</b>'; }?>
</div>
</div>